import React from 'react'

import { Route, Redirect } from 'react-router-dom'
let arr = []
arr.includes
import { isToken } from '../../api/storage'
import { Toast} from 'antd-mobile'
const AuthRoute = ({component: Component, ...test}) => {
    console.log(Component, '打印信息', test)
    return (
        <Route
            {...test}
            render={props => {
                // 是否需要登录
                const isLogin = isToken()
                console.log(isLogin)
                if (isLogin) {
                   return <Component {...props}/>
                } else {
                    Toast.show({
						icon: 'success',
						content: '暂未登录请先登录！',
						duration: 500,
					})
                   setTimeout(() => {
                        return (
                            <Redirect
                                to={{
                                    pathname: '/login',
                                    state: {
                                        from: props.location,
                                    },
                                }}
                            ></Redirect>
                        )
                   }, 500);
               }
            }}
        >
            
      </Route>
  )  
}

export default AuthRoute